//esta classe cuida somente do DRIVER;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBConnection {

//	configuracoes para usar o access
	private static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
	static String url = "jdbc:odbc:cursojava";
	static String user = "";
	static String password = "";

//	configuracoes para usar o mysql
//	private static String driver = "com.mysql.jdbc.Driver";
//	static String url = "jdbc:mysql://localhost:3306/curso";
//	static String user = "root";
//	static String password = "senha aqui";

	static {
		try {
			Class.forName(driver).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, user, password);
	}

	public static void closeConnection(Connection con) {
		if (con != null ) {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public static void closeStatement(Statement st) {
		if (st != null) {
			try {
				st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public static void closeResultSet(ResultSet rs) {
		if (rs != null) {
			try {
				((ResultSet)rs).close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
